package org.example.sys.security;

 import org.example.sys.utils.CommonUtil;
 import org.example.core.enums.BizErrorEnum;
 import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 没有登录异常处理
 * @author Calvin
 */
@Component
public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint {

    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e)
            throws IOException, ServletException {
        CommonUtil.responseError(response, BizErrorEnum.UNAUTHENTICATED.getCode(), BizErrorEnum.UNAUTHENTICATED.getDesc(),
                e.getMessage());
    }

}
